<?
print_r($POST);
#include('../rp2/global_functions.php');

$dbpass = "w9JwRoA";
$dbuser = "root";
$dbname = "rp2";
$dbhost = "209.25.134.4";

if(!$dbh_rp2 = pg_connect("dbname=$dbname host=$dbhost user=$dbuser password=$dbpass")) {
	$errorMsg = translate('int_error');
	include_once('errorMsg.html');
	exit;
}
// exit('Error Processing your request');

//-----------------------------------------------------
$sql['type'] = "SELECT";
$sql['params'] = "c.client_id,c.reseller_id,c.store_id,c.username,s.name,s.title,s.currency,s.products";
$sql['table'] = "clients c left join stores s using (store_id)";
$sql['where'] = "c.username='$client'";
$sql['options'] = "";
$sql['return'] = "hash";
//------------------------------------------------------
$client=sql_exec($sql,$dbh_rp2,'assoc');

if(!is_array($client)) {
	$errorMsg = translate('int_error');
	include_once('errorMsg.html');
	exit;
}
//exit('Error. Please Contact the support');

$products=$_POST[products];
$period=$_POST[period];
if(!is_array($products)) {
	$errorMsg = translate('int_error');
	include_once('errorMsg.html');
	exit;
}
//exit('Invalid parameters.');
$where= " and  (purchase_id='".implode("' or purchase_id='",array_keys($products))."')";
//------------------------------------------------------
$sql['type'] = "SELECT";
$sql['params'] = "*";
$sql['table'] = "purchases p1 left join products p on (p1.product_id=p.product_id)";
$sql['where'] = "store_id='$client[store_id]'". $where;
$sql['options'] = "";
$sql['return'] = "query";
$sql['return'] = "struct";
//------------------------------------------------------
$prod=sql_exec($sql,$dbh_rp2,'assoc');
$hiddens.="<input type=hidden name=action value='finish'>\n";
$hiddens.="<input type=hidden name='type' value='$type'>\n";
$hiddens.="<input type=hidden name='username' value='$client[username]'>\n";
$hiddens.="<input type=hidden name='period' value='$period'>\n";
$params[sid]=$sid;
$params['action']='renew';
$params['ren_complete']='Renewal Complete!';
$return_url="$baseURL/$webDIR/?".encode_params($params);
$hiddens.="<input type=hidden name='return_url' value='$return_url'>\n";
if(!is_array($prod)) {
	$errorMsg = translate('int_error');
	include_once('errorMsg.html');
	exit;
}
//exit("Parameters Error 3");
foreach($prod as $product){
	if($products[$product[purchase_id]]){
		switch($product[type]){
			case "plan":
				if(!$product[wholesale][$period][$client[currency]] && !$product[wholesale][$period][$client[currency]]===0 ) {
				  $errorMsg = translate('int_error');
	        include_once('errorMsg.html');
	        exit;				
				}
//				exit('Error 12');
				$total_price+=$product[wholesale][$period][$client[currency]];
			break;
			case "service":
				$q=get_service_quantity($product[name]);
				if(is_service_activated($product[name])) $total_price+=$product[wholesale][1][$client[currency]];
				else $total_price+=($product[wholesale][1][$client[currency]]*$period);
			break;
			case "domain":
				$total_price+=$product[wholesale][$period][$client[currency]];
			break;
			
		}
		$hiddens.="<input type=hidden name=products[$product[purchase_id]] value='".$products[$product[purchase_id]]."'>\n";
	}

}

?>
<br><br>
<table width=100% ><tr><td align=center valign=middle>
<table class='bTAble' cellspacing=0 cellpadding=10>
<form action='https://payments.duoservers.com/upgrade/renewal.php' name =form1 method=POST>
<?=$hiddens?>
<input type='hidden' name='reseller_authenticated' value='yes'>
<tr><th>Total Amount to be charged: <?=$SETTINGS[currencies][$client[currency]]." ".sprintf("%01.2f", $total_price)?></th></tr>
<tr><td class='order_td_left'>Payment Method:</td></tr><tr><td>
                                        <? if(!$_POST[processor]) $_POST[processor] ='cc';?>
                                        <input type=radio name=processor value='cc' <?if($_POST[processor]=='cc') echo 'checked'?>>Credit Card
                                        <input type=radio name=processor value='paypal' <?if($_POST[processor]=='paypal') echo 'checked'?>>PayPal
                                        <input type=radio name=processor value='wallet' <?if($_POST[processor]=='wallet') echo 'checked'?>>Wallet
                                </td></tr>
        <tr><td colspan=2>2Checkout.com, Inc. is an authorized retailer of SupremeServer</td></tr>
<tr><td colspan=10 align=center><input type=button value=Back onClick='window.history.go(-2)' class='buttonNormal' id='Back'>&nbsp;<input type=submit value='Next'  class='buttonNormal' id='Forward'></td></tr>
</table>
</td></tr></table>



